use std::fs;
use std::fs::File;
use std::io::{ErrorKind, Read};
fn main() -> Result<(), Box<dyn Error>> {
    // let _f = File::open("hello.txt");
    // let _f = match _f {
    //     Ok(file) => file,
    //     Err(err) => match err.kind() {
    //         ErrorKind::NotFound => match File::create("hello.txt") {
    //             Ok(fc) => fc,
    //             Err(e) => panic!("Problem creating the file: {:?}", e),
    //         },
    //         other_err => panic!("Problem opening the file: {:?}", other_err),
    //     },
    // };
    // let _f = File::open("hello.txt").unwrap();
    // let _f = File::open("hello.txt").expect("Failed to open hello.txt");
    // println!("hello");
    let f = File::open("hello.txt")?;

    Ok(())
}
// fn read_username_from_file() -> Result<String, io::Error> {
//     let _f = File::open("hello.txt");
//     let mut f = match _f {
//         Ok(file) => file,
//         Err(e) => return Err(e),
//     };
//     let mut s = String::new();
//     match f.read_to_string(&mut s) {
//         Ok(_) => Ok(s),
//         Err(e) => Err(e),
//     }
// }
fn read_username_from_file() -> Result<String, io::Error> {
    let mut f = File::open("hello.txt")?;
    let mut s = String::new();
    r.read_to_string(&mut s)?;
    Ok(s)
}
fn read_username_from_file1() -> Result<String, io::Error> {
    let mut s = String::new();
    File::open("hello.txt")?.read_to_string(&mut s)?;
    Ok(s)
}
fn read_username_from_file2() -> Result<String, io::Error> {
    fs::read_to_string("hello.txt")
}
